const puppeteer = require('puppeteer');
const url = 'https://movie.douban.com/tag/#/?sort=T&range=0,10&tags=%E7%A7%91%E5%B9%BB';

const sleep = time => new Promise(resolve => {
    setTimeout(resolve, time)
})



async function fn(){
    const browser = await puppeteer.launch({
        args: ['--no-sandbox'],
        dumpio: false
    });



    const page = await browser.newPage();
    await page.goto(url,{
        waitUntil: 'networkidle2'            // 页面加载完毕
    });


    await sleep(3000);

    await  page.waitForSelector('.more');

    for(let i = 0; i < 1 ; i++){
        await sleep(3300);
        await page.click('.more')
    }
    const result = await page.evaluate(()=>{
        var $ = window.$;
        console.log($);
        var items = $('.list-wp a');
        var links = [];

        if(items.length >=1){
            items.each((index, item)=>{
                let it = $(item);
                let doubanId = it.find('div').data('id');
                let title = it.find('.title').text();
                let rate = Number(it.find('.rete').text());
                let poster = it.find('img').attr('src').replace('s_ratio','l_ratio');
                links.push({
                    doubanId,
                    title,
                    rate,
                    poster
                })


            })
        }


        return links
    });




    browser.close()

    console.log(result)

};



fn()